

const handleMenuListData = (data = [], key, value) => {
  const obj = {
    text: '全部',
    value: ''
  }

  const list = data.map(item => {
    return {
      text: item[key],
      value: item[value]
    }
  })

  if(list[0] && list[0].text != '全部') {
    list.unshift({
      text: '全部',
      value: ''
    })
  }
  return list
}

 // 处理全屋 的数据  面积 风格,家庭组成, 户型
const handleAllHouseMenuListData = (data = { adsStyleDTOS: [], adsSpaceDTOS: [], familyNumbersDTOS: [], livingRoomsDTOS:[]}) => {
  // 风格
  const obj = {
    text: '全部',
    value: ''
  }
  let newStyleList = []
  if (data && data.adsStyleDTOS) {
    newStyleList = data.adsStyleDTOS.map(({ styleName, idx }) => { 
      const item = {
        text: styleName,
        value: idx
      }
      return item
    })
  }

  if (newStyleList[0].text != '全部') {
    newStyleList.unshift(obj)
  }
  
  // 空间
  let newSpaceList = []
  if (data && data.adsSpaceDTOS) {
    newSpaceList = data.adsSpaceDTOS.map(({idx,spaceName}) => {
      return {
        text: spaceName,
        value: idx
      }
    })
  }
  if (newSpaceList[0].text != '全部') {
    newSpaceList.unshift(obj)
  }
 
  // 家庭组成
  let newFamilyList = []
  if (data && data.familyNumbersDTOS) {
    newFamilyList = data.familyNumbersDTOS.map(({ idx, familyNumberName }) => {
      return {
        text: familyNumberName,
        value: idx
      }
    })
  }
  if (newFamilyList[0].text != '全部') {
    newFamilyList.unshift(obj)
  }
 
  // 居室
  let newLivingRoomsList = []
  if (data && data.livingRoomsDTOS) {
    newLivingRoomsList = data.livingRoomsDTOS.map(({ idx, livingRoomName }) => {
      return {
        text: livingRoomName,
        value: idx
      }
    })
  }
  if (newLivingRoomsList[0].text != '全部') {
    newLivingRoomsList.unshift(obj)
  }

  return {
    styleList: newStyleList,
    spaceList: newSpaceList,
    familyNumbersList: newFamilyList,
    livingRoomsList: newLivingRoomsList,
  }
}
 
const textAppend = (array = [])=>{
  let list = array.map(item =>{
     return item.text
  })
  return list.join(',')
}

const getValues = (array = [])=>{
  return array.map(item => {
    return item.value
  })
}

module.exports = {
  handleMenuListData,
  handleAllHouseMenuListData,
  textAppend,
  getValues
}
